﻿// =================================================================== 
// 项目说明
//====================================================================
// 文件： ERP_Lend.cs
// 创建时间：2016/12/3
// 负责人：
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using CRMMis.Model;
using CRMMis.IDAL;
using CommonLib.Model;


//注意：该文件自动生成，一般请不要手工修改。


namespace MSSQLDAL
{
    /// <summary>
    /// 数据层实例化接口类 借出表.
    /// </summary>
    public partial class ERP_LendDAL : IERP_LendDAL
    {
		
		 #region 变量声明（For update 和 Insert 时）
		// 声明静态变量 
		private const string PARA_LENDID =  "@LENDID";
		private const string PARA_LENDNO =  "@LENDNO";
		private const string PARA_STOREROOMID =  "@STOREROOMID";
		private const string PARA_INUSER =  "@INUSER";
		private const string PARA_INDATE =  "@INDATE";
		private const string PARA_CHECKUSER =  "@CHECKUSER";
		private const string PARA_CHECKDATE =  "@CHECKDATE";
		private const string PARA_STATE =  "@STATE";
		private const string PARA_REMARK =  "@REMARK";
		private const string PARA_OWNER =  "@OWNER";

		private const string SQL_UPDATE = "UPDATE ERP_LEND SET  LENDID= @LENDID, LENDNO= @LENDNO, STOREROOMID= @STOREROOMID, INUSER= @INUSER, INDATE= @INDATE, CHECKUSER= @CHECKUSER, CHECKDATE= @CHECKDATE, STATE= @STATE, REMARK= @REMARK, OWNER= @OWNER  WHERE LENDID = @LENDID ";
		private const string SQL_INSERT = "INSERT INTO ERP_LEND(LENDID, LENDNO, STOREROOMID, INUSER, INDATE, CHECKUSER, CHECKDATE, STATE, REMARK, OWNER ) values ( @LENDID, @LENDNO, @STOREROOMID, @INUSER, @INDATE, @CHECKUSER, @CHECKDATE, @STATE, @REMARK, @OWNER ) ";
		#endregion
		
		// 查询数据的sql串

		private string TableString;
		
		#region 构造函数


		/// <summary>
		/// ??????
		/// </summary>
		public ERP_LendDAL()
		{
			if (QueryDataString == "")
                TableString = "ERP_Lend SQL_A";
            else
                TableString = "(" + QueryDataString + ") SQL_A";
		}
		#endregion

        //-----------实例化接口函数-----------
		
		//------------增删改函数------------------- 
		
		#region Add 向数据库中插入一条新记录。

		/// <summary>
		/// 向数据库ERP_Lend中插入一条新记录。
		/// </summary>
		/// <param name="_ERP_LendModel">ERP_Lend??</param>
		/// <returns>影响的行数</returns>
		public int Add(CRMMis.Model.ERP_Lend _ERP_LendModel)
		{
			// 声明参数数组并赋值
			SqlParameter[] _param=
			{
				new SqlParameter(PARA_LENDID, SqlDbType.Int), 
				new SqlParameter(PARA_LENDNO, SqlDbType.VarChar), 
				new SqlParameter(PARA_STOREROOMID, SqlDbType.Int), 
				new SqlParameter(PARA_INUSER, SqlDbType.VarChar), 
				new SqlParameter(PARA_INDATE, SqlDbType.DateTime), 
				new SqlParameter(PARA_CHECKUSER, SqlDbType.VarChar), 
				new SqlParameter(PARA_CHECKDATE, SqlDbType.DateTime), 
				new SqlParameter(PARA_STATE, SqlDbType.Int), 
				new SqlParameter(PARA_REMARK, SqlDbType.VarChar), 
				new SqlParameter(PARA_OWNER, SqlDbType.VarChar)
			};			
			
			 _param[0].Value =  _ERP_LendModel.LendId;
			 _param[1].Value =  _ERP_LendModel.LendNo;
			 _param[2].Value =  _ERP_LendModel.StoreRoomId;
			 _param[3].Value =  _ERP_LendModel.InUser;
			 if (_ERP_LendModel.InDate==String.Empty) _param[4].Value = DBNull.Value; else _param[4].Value =  _ERP_LendModel.InDate;
			 _param[5].Value =  _ERP_LendModel.CheckUser;
			 if (_ERP_LendModel.CheckDate==String.Empty) _param[6].Value = DBNull.Value; else _param[6].Value =  _ERP_LendModel.CheckDate;
			 _param[7].Value =  _ERP_LendModel.State;
			 _param[8].Value =  _ERP_LendModel.Remark;
			 _param[9].Value =  _ERP_LendModel.Owner;
			
			//  返回
			return (int)SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, SQL_INSERT, _param);
		}
        
		#endregion
		
		#region Add 向数据库中插入一条新记录。带事务
        
		/// <summary>
		/// 向数据库ERP_Lend中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_ERP_LendModel">ERP_Lend实体</param>
		/// <returns>影响的行数</returns>
		public int Add(DBTransaction dbTrans,CRMMis.Model.ERP_Lend _ERP_LendModel)
		{
			// 声明参数数组并赋值
			SqlParameter[] _param=
			{
				new SqlParameter(PARA_LENDID, SqlDbType.Int), 
				new SqlParameter(PARA_LENDNO, SqlDbType.VarChar), 
				new SqlParameter(PARA_STOREROOMID, SqlDbType.Int), 
				new SqlParameter(PARA_INUSER, SqlDbType.VarChar), 
				new SqlParameter(PARA_INDATE, SqlDbType.DateTime), 
				new SqlParameter(PARA_CHECKUSER, SqlDbType.VarChar), 
				new SqlParameter(PARA_CHECKDATE, SqlDbType.DateTime), 
				new SqlParameter(PARA_STATE, SqlDbType.Int), 
				new SqlParameter(PARA_REMARK, SqlDbType.VarChar), 
				new SqlParameter(PARA_OWNER, SqlDbType.VarChar)
			};	
			
			 _param[0].Value =  _ERP_LendModel.LendId;
			 _param[1].Value =  _ERP_LendModel.LendNo;
			 _param[2].Value =  _ERP_LendModel.StoreRoomId;
			 _param[3].Value =  _ERP_LendModel.InUser;
			 if (_ERP_LendModel.InDate==String.Empty) _param[4].Value = DBNull.Value; else _param[4].Value =  _ERP_LendModel.InDate;
			 _param[5].Value =  _ERP_LendModel.CheckUser;
			 if (_ERP_LendModel.CheckDate==String.Empty) _param[6].Value = DBNull.Value; else _param[6].Value =  _ERP_LendModel.CheckDate;
			 _param[7].Value =  _ERP_LendModel.State;
			 _param[8].Value =  _ERP_LendModel.Remark;
			 _param[9].Value =  _ERP_LendModel.Owner;
			
			//  返回
			return (int)SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, SQL_INSERT, _param);
		}
        
		#endregion
		
		#region	Update 向数据表更新一条记录。	
        
		/// <summary>
		/// 向数据表ERP_Lend更新一条记录。
		/// </summary>
		/// <param name="_ERP_LendModel">_ERP_LendModel</param>
		/// <returns>影响的行数</returns>
		public int Update(CRMMis.Model.ERP_Lend _ERP_LendModel)
		{
			// 声明参数数组并赋值

			SqlParameter[] _param=
			{
				new SqlParameter(PARA_LENDID, SqlDbType.Int), 
				new SqlParameter(PARA_LENDNO, SqlDbType.VarChar), 
				new SqlParameter(PARA_STOREROOMID, SqlDbType.Int), 
				new SqlParameter(PARA_INUSER, SqlDbType.VarChar), 
				new SqlParameter(PARA_INDATE, SqlDbType.DateTime), 
				new SqlParameter(PARA_CHECKUSER, SqlDbType.VarChar), 
				new SqlParameter(PARA_CHECKDATE, SqlDbType.DateTime), 
				new SqlParameter(PARA_STATE, SqlDbType.Int), 
				new SqlParameter(PARA_REMARK, SqlDbType.VarChar), 
				new SqlParameter(PARA_OWNER, SqlDbType.VarChar)
			};	
			
			 _param[0].Value =  _ERP_LendModel.LendId;
			 _param[1].Value =  _ERP_LendModel.LendNo;
			 _param[2].Value =  _ERP_LendModel.StoreRoomId;
			 _param[3].Value =  _ERP_LendModel.InUser;
			 if (_ERP_LendModel.InDate==String.Empty) _param[4].Value = DBNull.Value; else _param[4].Value =  _ERP_LendModel.InDate;
			 _param[5].Value =  _ERP_LendModel.CheckUser;
			 if (_ERP_LendModel.CheckDate==String.Empty) _param[6].Value = DBNull.Value; else _param[6].Value =  _ERP_LendModel.CheckDate;
			 _param[7].Value =  _ERP_LendModel.State;
			 _param[8].Value =  _ERP_LendModel.Remark;
			 _param[9].Value =  _ERP_LendModel.Owner;
			
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, SQL_UPDATE, _param);
		}
        
		#endregion
		
		#region	Update 向数据表更新一条记录。带事务
        
		/// <summary>
		/// 向数据表ERP_Lend更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_ERP_LendModel">_ERP_LendModel</param>
		/// <returns>影响的行数</returns>
		public int Update(DBTransaction dbTrans,CRMMis.Model.ERP_Lend _ERP_LendModel)
		{
           // 声明参数数组并赋值

		    SqlParameter[] _param=
			{
				new SqlParameter(PARA_LENDID, SqlDbType.Int), 
				new SqlParameter(PARA_LENDNO, SqlDbType.VarChar), 
				new SqlParameter(PARA_STOREROOMID, SqlDbType.Int), 
				new SqlParameter(PARA_INUSER, SqlDbType.VarChar), 
				new SqlParameter(PARA_INDATE, SqlDbType.DateTime), 
				new SqlParameter(PARA_CHECKUSER, SqlDbType.VarChar), 
				new SqlParameter(PARA_CHECKDATE, SqlDbType.DateTime), 
				new SqlParameter(PARA_STATE, SqlDbType.Int), 
				new SqlParameter(PARA_REMARK, SqlDbType.VarChar), 
				new SqlParameter(PARA_OWNER, SqlDbType.VarChar)
			};		
			
			 _param[0].Value =  _ERP_LendModel.LendId;
			 _param[1].Value =  _ERP_LendModel.LendNo;
			 _param[2].Value =  _ERP_LendModel.StoreRoomId;
			 _param[3].Value =  _ERP_LendModel.InUser;
			 if (_ERP_LendModel.InDate==String.Empty) _param[4].Value = DBNull.Value; else _param[4].Value =  _ERP_LendModel.InDate;
			 _param[5].Value =  _ERP_LendModel.CheckUser;
			 if (_ERP_LendModel.CheckDate==String.Empty) _param[6].Value = DBNull.Value; else _param[6].Value =  _ERP_LendModel.CheckDate;
			 _param[7].Value =  _ERP_LendModel.State;
			 _param[8].Value =  _ERP_LendModel.Remark;
			 _param[9].Value =  _ERP_LendModel.Owner;
			
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, SQL_UPDATE, _param);
		}
        
		#endregion
        
		#region	Delete 根据主键，删除数据表中的一条记录	
        
		/// <summary>
		/// 根据主键，删除数据表ERP_Lend中的一条记录
		/// </summary>
	    /// <param name="lendId">lendId</param>
		/// <returns>影响的行数</returns>
		public int Delete(int lendId)
		{
			// 声明参数数组并赋值
			SqlParameter[] _param=
			{
				new SqlParameter("@lendId", SqlDbType.Int)
			};				
			_param[0].Value = lendId;
			
			string sqlStr="delete from ERP_Lend where  LendId=@lendId";
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, sqlStr, _param);;
		}
        
		#endregion
		
		#region	Delete 根据主键，删除数据表中的一条记录 带事务
        
		/// <summary>
		/// 根据主键，删除数据表ERP_Lend中的一条记录 带事务
		/// <param name="sp">事务对象</param>
	    /// <param name="LendId">lendId</param>
		/// <returns>影响的行数</returns>
		public int Delete(DBTransaction dbTrans,int lendId)
		{
			// 声明参数数组并赋值

			SqlParameter[] _param=
			{
				new SqlParameter("@lendId", SqlDbType.Int)
			};				
			_param[0].Value = lendId;

			string sqlStr="delete from ERP_Lend where  LendId=@lendId";
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, sqlStr,_param);;

		}
        
		#endregion
		
		#region	DeleteFK 根据条件串，删除数据表中的N条记录	
        
		/// <summary>
		/// 根据条件串，删除数据表ERP_Lend中的N条记录
		/// </summary>
	    /// <param name="sWhere">条件串</param>
		/// <returns>影响的行数</returns>
		public int DeleteFK(string sWhere)
		{
			string  sqlStr="delete from ERP_Lend";
			if (sWhere.Length>0)
				sqlStr += " where "+sWhere;
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, sqlStr);
		}
        
		#endregion
		
		#region	DeleteFK 删除数据表中的一条记录,带事务
        
		/// <summary>
		/// 删除数据表ERP_Lend中的一条记录,带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="sWhere">条件串</param>
		/// <returns>影响的行数</returns>
		public int DeleteFK(DBTransaction dbTrans,string sWhere)
		{
			string  sqlStr="delete from ERP_Lend";
			if (sWhere.Length>0)
				sqlStr += " where "+sWhere;
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, sqlStr);
		}
		
		#endregion
		
		
		//------------获取数据及模型函数

		
		#region Exists 检测是否存在该主键
        
		/// <summary>
        /// 检测是否存在该主键
        /// </summary>
        /// <param name="int lendId" 主键列表</param>
        /// <returns>是/否</returns>
		public bool Exists(int lendId)
		{
			// 声明参数数组并赋值

			SqlParameter[] _param=
			{
				new SqlParameter("@lendId", SqlDbType.Int)
			};				
			_param[0].Value = lendId;
			
            string sqlStr="select Count(*) from ERP_Lend where  LendId=@lendId and LendId=@lendId";
						
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

		#endregion

		#region GetModel 根据主键ID,得到数据实体
        
        /// <summary>
		/// 根据主键ID,得到 erp_lend 数据实体
		/// </summary>
		/// <param name="int lendId" 主键列表</param>
		/// <returns>erp_lend 数据实体</returns>
		public CRMMis.Model.ERP_Lend GetModel(int lendId )
		{
			CRMMis.Model.ERP_Lend _obj=null;
			// 声明参数数组并赋值
            
			SqlParameter[] _param=
			{
				new SqlParameter("@lendId", SqlDbType.Int)
			};				
			_param[0].Value = lendId;
			
			string sqlStr="select * from ERP_Lend where  LendId=@lendId";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(Conn.SqlConnStr,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=PopulateERP_LendModelFromDr(dr);
				}
			}
			return _obj;
		}
        
		#endregion
        
        #region GetModel where条件,得到数据实体
        /// <summary>
        /// 根据where条件,得到 erp_lend 数据实体
        /// <para>如果存在多条，则返回第一条</para>
        /// </summary>
        /// <param name="sWhere" where条件</param>
        /// <returns> erp_lend 数据实体</returns>
        public CRMMis.Model.ERP_Lend GetModel(string sWhere)
        {
            CRMMis.Model.ERP_Lend _obj = null;
            
            string sqlStr = "select * from ERP_Lend where 1=1 ";
            if (!string.IsNullOrEmpty(sWhere))
                sqlStr += (" and " + sWhere);
            using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConnStr, CommandType.Text, sqlStr))
            {
                if (dr.Read())
                {
            		_obj=PopulateERP_LendModelFromDr(dr);
                }
            }
            return _obj;
        }
        #endregion
		
        #region GetModel 根据主键ID,得到数据实体，带事务
        
        /// <summary>
		/// 根据主键ID,得到 erp_lend 数据实体
		/// </summary>
		/// <param name="int lendId" 主键列表</param>
		/// <returns>erp_lend 数据实体</returns>
		public CRMMis.Model.ERP_Lend GetModel(DBTransaction dbTrans,int lendId )
		{
			CRMMis.Model.ERP_Lend _obj=null;
			// 声明参数数组并赋值
            
			SqlParameter[] _param=
			{
				new SqlParameter("@lendId", SqlDbType.Int)
			};				
			_param[0].Value = lendId;
			
			string sqlStr="select * from ERP_Lend where  LendId=@lendId";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(dbTrans.sql_trans,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=PopulateERP_LendModelFromDr(dr);
				}
			}
			return _obj;
		}
        
		#endregion
        
        #region GetModel where条件,得到数据实体，带事务
        /// <summary>
        /// 根据where条件,得到 erp_lend 数据实体
        /// <para>如果存在多条，则返回第一条</para>
        /// </summary>
        /// <param name="sWhere" where条件</param>
        /// <returns> erp_lend 数据实体</returns>
        public CRMMis.Model.ERP_Lend GetModel(DBTransaction dbTrans,string sWhere)
        {
            CRMMis.Model.ERP_Lend _obj = null;
            
            string sqlStr = "select * from ERP_Lend where 1=1 ";
            if (!string.IsNullOrEmpty(sWhere))
                sqlStr += (" and " + sWhere);
            using (SqlDataReader dr = SqlHelper.ExecuteReader(dbTrans.sql_trans, CommandType.Text, sqlStr))
            {
                if (dr.Read())
                {
            		_obj=PopulateERP_LendModelFromDr(dr);
                }
            }
            return _obj;
        }
        #endregion
		
		#region ----根据DataRow,得到 数据实体
		/// <summary>
		/// 得到  erp_lend 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>erp_lend 数据实体</returns>
		public CRMMis.Model.ERP_Lend PopulateERP_LendModelFromDr(DataRow row)
		{
			CRMMis.Model.ERP_Lend Obj = new CRMMis.Model.ERP_Lend();
			if(row!=null)
			{
				Obj.LendId = (( row["LendId"])==DBNull.Value)?0:Convert.ToInt32( row["LendId"]);
				Obj.LendNo =  row["LendNo"].ToString();
				Obj.StoreRoomId = (( row["StoreRoomId"])==DBNull.Value)?0:Convert.ToInt32( row["StoreRoomId"]);
				Obj.InUser =  row["InUser"].ToString();
				Obj.InDate =  row["InDate"].ToString();
				Obj.CheckUser =  row["CheckUser"].ToString();
				Obj.CheckDate =  row["CheckDate"].ToString();
				Obj.State = (( row["State"])==DBNull.Value)?0:Convert.ToInt32( row["State"]);
				Obj.Remark =  row["Remark"].ToString();
				Obj.Owner =  row["Owner"].ToString();
			}
			else
			{
				return null;
			}
			return Obj;
		}
		#endregion
		
		#region ----根据IDataReader,得到 数据实体
        
        /// <summary>
		/// 得到  erp_lend 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>erp_lend 数据实体</returns>
		public CRMMis.Model.ERP_Lend PopulateERP_LendModelFromDr(IDataReader dr)
		{
			CRMMis.Model.ERP_Lend Obj = new CRMMis.Model.ERP_Lend();
			
				Obj.LendId = (( dr["LendId"])==DBNull.Value)?0:Convert.ToInt32( dr["LendId"]);
				Obj.LendNo =  dr["LendNo"].ToString();
				Obj.StoreRoomId = (( dr["StoreRoomId"])==DBNull.Value)?0:Convert.ToInt32( dr["StoreRoomId"]);
				Obj.InUser =  dr["InUser"].ToString();
				Obj.InDate =  dr["InDate"].ToString();
				Obj.CheckUser =  dr["CheckUser"].ToString();
				Obj.CheckDate =  dr["CheckDate"].ToString();
				Obj.State = (( dr["State"])==DBNull.Value)?0:Convert.ToInt32( dr["State"]);
				Obj.Remark =  dr["Remark"].ToString();
				Obj.Owner =  dr["Owner"].ToString();
			
			return Obj;
		}
        
		#endregion
        
		#region GetNewID 通过种子得到唯一ID,对单主键有效单，如果该表为多主键，则返回第一主键
        
		/// <summary>
        ///  通过种子得到唯一ID,对单主键有效单，如果该表为多主键，则返回第一主键
        /// </summary>
        /// <param name="lendId">lendId</param>
        /// <returns>int</returns>
		public int GetNewID()
		{
			return  DBCommon.GetNewIDForTable("ERP_Lend","ERP_Lend","");
		}
        
		#endregion

		#region	GetMaxID 得到最大ID	
		/// <summary>
		/// 得到最大ID
		/// </summary>
        /// <param name="lendId">lendId</param>
        /// <returns>int</returns>
		public int GetMaxID()
		{
			return  0;
		}
		#endregion
		
		#region	GetList 得到数据表指定字段列表的所有记录，可排序，
		/// <summary>
		/// 得到数据表ERP_Lend所有记录，可排序
		/// </summary>
        /// <param name="sWhere">条件字符串</param>
        /// <param name="sOder">排序字段</param>
		/// <returns>DataSet</returns>
		public DataSet GetList(string sWhere, string sOder)
		{
			string	sqlStr="select * from "+TableString;
				
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			if (sOder.Length > 0)
				sqlStr += " order by " + sOder;
				
			WriteLog("ERP_LendDAL", "GetList(string sWhere, string sOder)", sqlStr);
			
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion
        
        #region	GetList 得到数据表指定字段列表的所有记录，可排序，带事务的查询
		/// <summary>
		/// 得到数据表ERP_Lend所有记录，可排序，带事务的查询
		/// </summary>
        /// <param name="dbTrans">事务对象</param>
        /// <param name="sWhere">条件字符串</param>
        /// <param name="sOder">排序字段</param>
		/// <returns>DataSet</returns>
		public DataSet GetList(DBTransaction dbTrans, string sWhere, string sOder)
		{
			string	sqlStr="select * from "+TableString;
				
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			if (sOder.Length > 0)
				sqlStr += " order by " + sOder;
				
			WriteLog("ERP_LendDAL", "GetList(string sWhere, string sOder)", sqlStr);
			
			return SqlHelper.ExecuteDataset(dbTrans.sql_trans,CommandType.Text,sqlStr);
		}
		#endregion

		#region GetPageList 根据条件和页号得到某页的记录集,+排序
		/// <summary>
		/// 根据条件和页号得到某页的记录集,+排序
		/// </summary>
        /// <param name="iPageSize">每页记录数</param>
		/// <param name="iPageIndex">页号</param>
		/// <param name="sWhere">条件字符串</param>
		/// <param name="sOder">排序字段</param>
        /// <returns>DataSet</returns>
		public DataSet GetPageList(int iPageSize,int iPageIndex, string sWhere, string sOder)
		{
			if (sOder.Length <=0)
				sOder = "LendId";
				
			string	sqlStr="select * from (select ROW_NUMBER() OVER(order by "+sOder+" ) as row, * from "+TableString;
			
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			sqlStr += ") SQL1 where row between "+ Convert.ToString(iPageSize*(iPageIndex-1)+1) +" and "+Convert.ToString(iPageSize*iPageIndex);
			
			WriteLog("ERP_LendDAL", "GetPageList(int iPageSize,int iPageIndex, string sWhere, string sOder)", sqlStr);
			
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion
		
		#region GetRecorderRowNum 判断某条记录所在的行号
		/// <summary>
		/// 判断某条记录所在的行号，调用者自己计算页号和行号
		/// </summary>
        /// <param name="sWhere">记录显示的条件</param>
        /// <param name="sOder">排序条件</param>
        /// <param name="iPageSize">每页记录数</param>
		/// <param name="主键列表">主键列表，需定位记录的键值</param>
        /// <returns>int 页码</returns>
		public int GetRecorderRowNum(string sWhere, string sOder, int iPageSize, int lendId)
		{
			if (sOder.Length <=0)
				sOder = "LendId";
				
			// 声明参数数组并赋值
			SqlParameter[] _param=
			{
				new SqlParameter("@lendId", SqlDbType.Int)
			};				
			_param[0].Value = lendId;
			
			string	sqlStr="select row from (select ROW_NUMBER() OVER(order by "+sOder+" ) as row, lendId from "+TableString;
			
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
				
			sqlStr = sqlStr + ") SQL1 where  LendId=@lendId";
			
			WriteLog("ERP_LendDAL", "GetRecorderRowNum(string sWhere, string sOder, int iPageSize, int lendId)", sqlStr);
			
			return Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr,_param));
		}
		#endregion
		
				
		#region GetRecorderCount 得到符合条件记录集的记录条数
		/// <summary>
		/// 得到符合条件记录集的记录条数
		/// </summary>
        /// <param name="FlowProcessId">流程ID</param>
		/// <param name="sWhere">条件字符串</param>
        /// <returns>int 记录数</returns>
		public int GetRecorderCount(string FlowProcessId, string sWhere)
		{
			string sqlStr ="";
			
			if (FlowProcessId.Length > 0)
            	sqlStr="select Count(*) from "+TableString+" left join view_wfInstance_state SQL_B on SQL_a.work_id=SQL_b.work_id";
			else
				sqlStr="select Count(*) from "+TableString;
				
			if (sWhere.Length>0)
				sqlStr += " where " + sWhere;
				
			WriteLog("ERP_LendDAL", "GetRecorderCount(string FlowProcessId, string sWhere)", sqlStr);
			
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr));
		}
		#endregion				
		
		#region----------自定义实例化接口函数----------
		#endregion
		
		#region----------日志-------------------------
		    public void WriteLog(string classname, string methodname, string sql)
			{
				log4net.ILog logDebug = log4net.LogManager.GetLogger("DebugLogger");
				logDebug.Debug("[ClassName]:" + classname + "\r\n[MethodeName]:" + methodname + "\r\n[SqlStr]:\r\n" + sql);
			}
		#endregion
    }
}
